package com.carol.lmsbe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carol.lmsbe.entity.EquipmentApplication;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 设备申请Mapper接口
 */
@Mapper
public interface EquipmentApplicationMapper extends BaseMapper<EquipmentApplication> {

    /**
     * 根据申请人ID查询申请列表
     */
    @Select("SELECT ea.*, u.real_name as applicant_name, l.name as laboratory_name " +
            "FROM equipment_application ea " +
            "LEFT JOIN user u ON ea.applicant_id = u.id " +
            "LEFT JOIN laboratory l ON ea.laboratory_id = l.id " +
            "WHERE ea.applicant_id = #{applicantId}")
    List<EquipmentApplication> selectByApplicantId(@Param("applicantId") Long applicantId);

    /**
     * 根据状态查询申请列表
     */
    @Select("SELECT ea.*, u.real_name as applicant_name, l.name as laboratory_name " +
            "FROM equipment_application ea " +
            "LEFT JOIN user u ON ea.applicant_id = u.id " +
            "LEFT JOIN laboratory l ON ea.laboratory_id = l.id " +
            "WHERE ea.status = #{status}")
    List<EquipmentApplication> selectByStatus(@Param("status") String status);

    /**
     * 根据实验室ID查询申请列表
     */
    @Select("SELECT ea.*, u.real_name as applicant_name, l.name as laboratory_name " +
            "FROM equipment_application ea " +
            "LEFT JOIN user u ON ea.applicant_id = u.id " +
            "LEFT JOIN laboratory l ON ea.laboratory_id = l.id " +
            "WHERE ea.laboratory_id = #{laboratoryId}")
    List<EquipmentApplication> selectByLaboratoryId(@Param("laboratoryId") Long laboratoryId);
}
